/************************************************************
 * Copyright (C), 2022-2030, ripnano. Co., Ltd.
 * FileName:        form_self_check.h
 * Author:          Dan Yin
 * Date:            2024-11-13
 * Description:     the class of self-check page
 * Version:         1.0.0.0
 **********************************************************/

#ifndef FORM_SELF_CHECK_H
#define FORM_SELF_CHECK_H

// add necessary includes here
#include "ui/defines/global.h"
#include "utils/can/can_bll_t1c.h"
#include "utils/firmware/firmware_bll.h"

namespace Ui {
class FormSelfCheck;
}

class FormSelfCheck : public QWidget
{
    Q_OBJECT

public:
    // Get an instance of "FormSelfCheck" class, if exist, return it
    static FormSelfCheck* getInstance(QWidget *pParent = nullptr);

    // The default destructor
    virtual ~FormSelfCheck();

protected:
    // Triggers an event before it is switch language
    void changeEvent(QEvent *event);

signals:
    void signalStartupSelfTest();

    void signalSelfCheckCompleted(int nErrCode);

    void signalUpdateProgressBarValue(int nRowIdx, int nValue, QString sInfo = "");

private slots:
    void on_pushButton_SkipIt_clicked();

    void slotStartupSelfTest();

    void slotUpdateProgressBarValue(int nRowIdx, int nValue, QString sInfo = "");

private:
    // The default constructor
    FormSelfCheck(QWidget *parent = nullptr);

    // After constructing object, initialize the object
    void _initObj();

    // Init the window style
    void _initUi();

    // Deal with all device
    int _procDetectAll();

    // Deal with detect CAN device
    int _procDetectCAN(CanBLL_T1C *pSerialbusBLL);

    // Deal with reset all motors
    int _procResetMotors(CanBLL_T1C *pSerialbusBLL);

    // Deal with detect pipette device
    int _procDetectPipette(CanBLL_T1C *pSerialbusBLL);

    // Deal with detect motion device
    int _procDetectMotion(CanBLL_T1C *pSerialbusBLL);

    // Deal with detect heating device
    int _procDetectHeating(CanBLL_T1C *pSerialbusBLL);

private:
    Ui::FormSelfCheck *ui = nullptr;

    bool    m_bSkipDetect = false;
    bool    m_bMotorReseted = false;
};

#endif // FORM_SELF_CHECK_H
